package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.UserOpenPlatformInfoAddRequest;
import com.frogs.ucenter.v1.request.UserOpenPlatformInfoListRequest;
import com.frogs.ucenter.v1.service.UserOpenPlatformInfoService;
import com.frogs.ucenter.v1.util.ApiConstants;

/**
 * 
 *
 * @author lijian
 * @version 2014年3月23日 - 下午3:42:58
 */
@Controller(ApiConstants.VERSION+"userOpenPlatformInfoController")
@RequestMapping("/"+ApiConstants.VERSION)
public class UserOpenPlatformInfoController extends BaseController3 {

	private static final String ROOT = "/user";
	private static final String USER_OPEN_PLATFORM_ADD = ROOT + "/openPlatform/add";
	private static final String USER_OPEN_PLATFORM_LIST = ROOT + "/openPlatform/list";
	

	@Resource(name=ApiConstants.VERSION + "userOpenPlatformInfoService")
	private UserOpenPlatformInfoService userOpenPlatformInfoService;
	
	/**
	 * 新增用户开放台平信息接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/user/openPlatform/add.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	
	@RequestMapping(USER_OPEN_PLATFORM_ADD)
	public Response userOpenPlatformInfoAdd(HttpServletRequest request) {
		Response response;
		try {
			UserOpenPlatformInfoAddRequest userOpenPlatformInfoAddRequest = new UserOpenPlatformInfoAddRequest();
			userOpenPlatformInfoAddRequest.parse(request);
			response = userOpenPlatformInfoService.insert(userOpenPlatformInfoAddRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 查询用户开放台平信息接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/user/openPlatform/list.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	
	@RequestMapping(USER_OPEN_PLATFORM_LIST)
	public Response userOpenPlatformList(HttpServletRequest request) {
		Response response;
		try {
			UserOpenPlatformInfoListRequest userOpenPlatformInfoListRequest = new UserOpenPlatformInfoListRequest();
			userOpenPlatformInfoListRequest.parse(request);
			response = userOpenPlatformInfoService.getUserOpenPlatformList(userOpenPlatformInfoListRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
}
